//
//  DeviceDataCell.m
//  Fantasia
//
//  Created by kongkong on 2016/12/25.
//  Copyright © 2016年 Kongkong. All rights reserved.
//

#import "DeviceDataCell.h"

#define FULL_WIDTH [UIScreen mainScreen].bounds.size.width
#define CELL_HEIGHT 40

@interface DeviceDataCell ()
@property(nonatomic, strong) UILabel *textValue;
@property(nonatomic, strong) UIView *boolLogoValue;
@end

@implementation DeviceDataCell

- (void)reloadWithData:(DataModel *)dataModel {
    self.textLabel.text = dataModel.title;
    self.textLabel.textColor = [UIColor blackColor];
    
    switch (dataModel.type) {
        case DataType_String: {
            self.accessoryView = self.textValue;
            self.textValue.text = dataModel.textValue;
        }
            break;
        case DataType_BoolLogo: {
            self.accessoryView = self.boolLogoValue;
            self.boolLogoValue.backgroundColor = dataModel.boolLogoColor;
            self.textLabel.textColor = dataModel.boolLogoColor;
        }
            break;
    }
}

- (UILabel *)textValue {
    if (!_textValue) {
        _textValue = [[UILabel alloc] initWithFrame:CGRectMake(0, 0, 150, CELL_HEIGHT-10)];
        _textValue.textColor = [UIColor grayColor];
        _textValue.textAlignment = NSTextAlignmentRight;
    }
    return _textValue;
}

- (UIView *)boolLogoValue {
    if (!_boolLogoValue) {
        UIView *view = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 10, 10)];
        view.layer.masksToBounds = YES;
        view.layer.cornerRadius = 2;
        _boolLogoValue = view;
    }
    return _boolLogoValue;
}

+ (CGFloat)heightWithData:(DataModel *)data {
    return CELL_HEIGHT;
}

@end
